import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:zhrs/mainpage/webviewpage.dart';
import 'package:zhrs/utils/windowsSize.dart';
import 'package:zhrs/Model/exploremessage.dart';
import 'package:zhrs/Model/message.dart';
class Explorebutton extends StatefulWidget
{
  int index;
  String upordown;
  List<exploremanmessage1> exploremessage;
  Function reset;
  Explorebutton({this.upordown,this.exploremessage,this.reset}){
  }
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _Explorebutton();
  }
}
class _Explorebutton extends State<Explorebutton>
{
  double top;

  _Explorebutton();

 @override
  Widget build(BuildContext context) {
         if(widget.upordown=="up")
           {
             top=windowsSize.mapViewWidth*0.07;
           }
         else
           {
             top=windowsSize.mapViewWidth*1.13;
           }
    // TODO: implement build
    return Padding(
        padding: EdgeInsets.only(top: this.top ),
          child: Container(
             //color: Colors.white30,
             width: windowsSize.mapViewWidth,
             height: windowsSize.mapViewHeight*0.2 ,
           child: Row(
             children:
             widget.exploremessage.map((exploremanmessage1){

               if(exploremanmessage1.title=="null")
                 return Container(
                   width: windowsSize.mapViewWidth/5,
                   height: windowsSize.mapViewWidth/5,

                 );

               if(exploremanmessage1.upordown=="up"){
                 if(exploremanmessage1.index==3)
                 {
                   return   Padding(
                       padding:  EdgeInsets.only(top: exploremanmessage1.top ,left: 5,right: 5 ),
                       child:  Column(
                         children: <Widget>[
                           new ClipRRect(
                             borderRadius: const BorderRadius.all(const Radius.circular(90.0)),
                             child:
                             new GestureDetector(
                             onTap: ()
                             {

                                 if(exploremanmessage1.Url!=null)
                                 {
                                   widget.reset(url:exploremanmessage1.Url);
                                //   Navigator.push(context, new MaterialPageRoute(

                                //     builder :(context)=>new Webviewpage(url:exploremanmessage1.Url ,),
                                //   ));
                                 }
                                 else
                                 {
                                   showCupertinoDialogs(context, "建设中,敬请期待...");
                                 }

                             },
                                   child:   Container(
                                     color: exploremanmessage1.color,
                                     width: windowsSize.mapViewWidth/5-10,
                                     height: windowsSize.mapViewWidth/5-10,
                                     child:Center(
                                       child: Text(exploremanmessage1.title,textAlign: TextAlign.center,style: TextStyle(color: Colors.white,decoration: TextDecoration.none,fontSize: 13),),
                                     ) ,
                                   ),)
                           ),
                         ],
                       )
                   );
                 }
                 if(exploremanmessage1.top==10.0)
                 {
                   exploremanmessage1.top= windowsSize.mapViewHeight*0.18-windowsSize.mapViewWidth/5+10;
                 }
                 return  Padding(
                   padding:  EdgeInsets.only(top:exploremanmessage1.top,left: 5,right: 5 ),
                   child:  new ClipRRect(
                     borderRadius: const BorderRadius.all(const Radius.circular(90.0)),
                     child:
                         new GestureDetector(
                             onTap: ()
                                 {

                                     if(exploremanmessage1.Url!=null)
                                     {
                                       widget.reset(url:exploremanmessage1.Url);
                                    //   Navigator.push(context, new MaterialPageRoute(

                                      //   builder :(context)=>new Webviewpage(url:exploremanmessage1.Url ,),
                                     //  ));
                                     }
                                     else
                                     {
                                       showCupertinoDialogs(context, "建设中,敬请期待...");
                                     }


                               },
                         child:    Container(
                           color: exploremanmessage1.color,
                           width: windowsSize.mapViewWidth/5-10,
                           height: windowsSize.mapViewWidth/5-10,
                           child:Center(
                             child: Text(exploremanmessage1.title,textAlign: TextAlign.center,style: TextStyle(color: Colors.white,decoration: TextDecoration.none,fontSize: 13),),
                           ) ,
                         ),

                         )
                   ),
                 );
               }
          else{
                 if(exploremanmessage1.index==1||exploremanmessage1.index==5)
                 {
                   return   Padding(
                       padding:  EdgeInsets.only(top: exploremanmessage1.top ,left: 5,right: 5 ),
                       child:  Column(
                         children: <Widget>[
                           new ClipRRect(
                             borderRadius: const BorderRadius.all(const Radius.circular(90.0)),
                             child:
                             new GestureDetector(
                             onTap: ()
                             {

                                 if(exploremanmessage1.Url!=null)
                                 {
                                   widget.reset(url:exploremanmessage1.Url);
                                   //Navigator.push(context, new MaterialPageRoute(

                                    // builder :(context)=>new Webviewpage(url:exploremanmessage1.Url ,),
                                   //));
                                 }
                                 else
                                 {
                                   showCupertinoDialogs(context, "建设中,敬请期待...");
                                 }

                             },
                              child: Container(
                                color: exploremanmessage1.color,
                                width: windowsSize.mapViewWidth/5-10,
                                height: windowsSize.mapViewWidth/5-10,
                                child:Center(
                                  child: Text(exploremanmessage1.title,textAlign: TextAlign.center,style: TextStyle(color: Colors.white,decoration: TextDecoration.none,fontSize: 13),),
                                ) ,
                              ),
                            )
                           ),
                         ],
                       )
                   );
                 }

                 if(exploremanmessage1.top==10.0)
                 {
                   exploremanmessage1.top= windowsSize.mapViewHeight*0.18-windowsSize.mapViewWidth/5+10;
                 }
                 return  Padding(
                   padding:  EdgeInsets.only(top:  exploremanmessage1.top,left: 5,right: 5 ),
                   child:  new ClipRRect(
                     borderRadius: const BorderRadius.all(const Radius.circular(90.0)),
                     child:new GestureDetector(
                             onTap: ()
                                   {

                                       if(exploremanmessage1.Url!=null)
                                       {
                                         widget.reset(url:exploremanmessage1.Url);
                                        // Navigator.push(context, new MaterialPageRoute(

                                         //  builder :(context)=>new Webviewpage(url:exploremanmessage1.Url ,),
                                        // ));
                                       }
                                       else
                                       {
                                         showCupertinoDialogs(context, "建设中,敬请期待...");
                                       }

                                          },
                                         child:  Container(
                                         color: exploremanmessage1.color,
                                         width: windowsSize.mapViewWidth/5-10,
                                         height: windowsSize.mapViewWidth/5-10,
                               child:Center(
                          child: Text(exploremanmessage1.title,textAlign: TextAlign.center,style: TextStyle(color: Colors.white,decoration: TextDecoration.none,fontSize: 13),),
                        ) ,
                      ),
                        )


                   ),
                 );
               }
               return null;
          }).toList()

        ),
      ),
    );
  }
}